package com.ruoyi.car.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.car.domain.CheCarType;
import com.ruoyi.car.service.ICheCarTypeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 车辆型号Controller
 * 
 * @author ruoyi
 * @date 2024-06-05
 */
@RestController
@RequestMapping("/cartype")
public class CheCarTypeController extends BaseController
{
    @Autowired
    private ICheCarTypeService cheCarTypeService;

    /**
     * 查询车辆型号列表
     */
    @RequiresPermissions("car:cartype:list")
    @GetMapping("/list")
    public TableDataInfo list(CheCarType cheCarType)
    {
        startPage();
        List<CheCarType> list = cheCarTypeService.selectCheCarTypeList(cheCarType);
        return getDataTable(list);
    }

    /**
     * 导出车辆型号列表
     */
    @RequiresPermissions("car:cartype:export")
    @Log(title = "车辆型号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CheCarType cheCarType)
    {
        List<CheCarType> list = cheCarTypeService.selectCheCarTypeList(cheCarType);
        ExcelUtil<CheCarType> util = new ExcelUtil<CheCarType>(CheCarType.class);
        util.exportExcel(response, list, "车辆型号数据");
    }

    /**
     * 获取车辆型号详细信息
     */
//    @RequiresPermissions("car:cartype:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cheCarTypeService.selectCheCarTypeById(id));
    }

    /**
     * 新增车辆型号
     */
    @RequiresPermissions("car:cartype:add")
    @Log(title = "车辆型号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CheCarType cheCarType)
    {
        return toAjax(cheCarTypeService.insertCheCarType(cheCarType));
    }

    /**
     * 修改车辆型号
     */
    @RequiresPermissions("car:cartype:edit")
    @Log(title = "车辆型号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CheCarType cheCarType)
    {
        return toAjax(cheCarTypeService.updateCheCarType(cheCarType));
    }

    /**
     * 删除车辆型号
     */
    @RequiresPermissions("car:cartype:remove")
    @Log(title = "车辆型号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cheCarTypeService.deleteCheCarTypeByIds(ids));
    }
}
